package com.nearbymap.maps;

import java.util.List;

import org.springframework.stereotype.Service;

import com.nearbymap.model.LatLng;

@Service
public class StaticMapsService {
	private static final String DEFAULT_CENTER = "Singapore";

	public String getMapUri() {
		StringBuffer uriBuffer = new StringBuffer("http://maps.googleapis.com/maps/api/staticmap?center=")
				.append(DEFAULT_CENTER).append("&size=640x400&sensor=false");
		return uriBuffer.toString();
	}
	
	public String getMapUri(String polyline, LatLng origin1, LatLng origin2, LatLng destination) {
		StringBuffer uriBuffer = new StringBuffer("http://maps.googleapis.com/maps/api/staticmap?size=640x400&sensor=false");
		if(polyline != null) {
			uriBuffer.append("&path=weight:5%7Cenc:").append(polyline);
		}
		uriBuffer.append("&markers=").append(origin1).append("%7C").append(destination).append("%7C").append(origin2);
		System.out.println("MapsUrl: " + uriBuffer.toString());
		return uriBuffer.toString();
	}
	public String getMapUri(String polyline, List<LatLng> markers) {
		StringBuffer uriBuffer = new StringBuffer("http://maps.googleapis.com/maps/api/staticmap?size=640x400&sensor=false");
		if(polyline != null) {
			uriBuffer.append("&path=weight:5%7Cenc:").append(polyline);
		}
		for (LatLng m : markers) {
			uriBuffer.append("&markers=").append(m);
		}
		System.out.println("MapsUrl: " + uriBuffer.toString());
		return uriBuffer.toString();
	}
}
